<template>
  <div class="app-container">
    <el-form
      v-loading="loading"
      ref="eventsForm"
      label-position="right"
      label-width="120px"
      :model="eventsForm"
      size="small"
      :rules="eventsRules"
    >
      <div class="blockquote-box">最低提现配置</div>
      <div class="form-box">
        <el-row>
          <el-col :span="12">
            <el-form-item label="提现费率" prop="rate" class="form-box-item">
          <el-input
            clearable
            show-word-limit
            placeholder="费率（%）"
            v-model="eventsForm.rate"
            type="number"
            max="100"
            min="0"
            style="width: 450px;"
          >
          </el-input>
          <div class="tipbox">商户提现的手续费，单位为%，例：100*(输入的值)% = 商户的手续费</div>
        </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item
          prop="min_price"
          label="最低提现额"
          class="form-box-item"
        >
          <el-input
            placeholder="提现金额"
            v-model="eventsForm.min_price"
            type="number"
            min="0"
            style="width: 450px;"
          ></el-input>
          <div class="tipbox">商户每次提现金额必须大于最低提现金额</div>
        </el-form-item>
          </el-col>
        </el-row>  
       
      
        <!-- <el-form-item
          prop="min_price"
          label="最低手续费"
          class="form-box-item"
        >
          <el-input
            placeholder="最低手续费"
            v-model="eventsForm.min_price"
            type="number"
            min="0"
            style="width: 450px;"
          ></el-input>
          <div class="tipbox">商户提现时计算的手续费小于【配置金额】时按照【配置金额】计算;例：商户提现100*0.3%=0.3系统按照【配置金额】收费</div>
        </el-form-item> -->
        <div class="blockquote-box">免额配置</div>
        <el-row>
          <el-col :span="12">
            <el-form-item label="免手续费" class="form-box-item">
          <!-- <el-switch
            v-model="eventsForm.is_charge"
            active-color="#13ce66"
            active-value="1"
            inactive-value="2"
          ></el-switch> -->
          <el-radio-group v-model="eventsForm.is_charge">
            <el-radio label="1">开启</el-radio>
            <el-radio label="2">关闭</el-radio>
          </el-radio-group>
          <div class="tipbox" v-if="eventsForm.is_charge == '1'">
            开启后: 平台可为商户设置一定额度的免费提现额度，超出免费额度后系统按照提现费率收取提现通道手续费
          </div>
        </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item
          v-if="eventsForm.is_charge == '1'"
          prop="avoid_charge_price"
          label="统一免额度"
          class="form-box-item"
        >
          <el-input
            placeholder="免费提现额度"
            v-model="eventsForm.avoid_charge_price"
            style="width: 450px;"
          ></el-input>
          <div class="tipbox">
            平台为商家提供一定额度的免费提现额度，超出免费额度后系统按照提现费率收取提现手续费
          </div>
        </el-form-item>
          </el-col>
        </el-row>  
       
       
        <div class="blockquote-box">提现审核配置</div>
        <el-form-item label="审核配置" required class="form-box-item">
          <el-radio-group v-model="eventsForm.is_check">
            <el-radio label="1">人工审核</el-radio>
            <el-radio label="2">自动审核</el-radio>
          </el-radio-group>
          <div class="tipbox">使用系统审核时，系统自动审核商户的提现金额是否满足提现要求，不满足时系统自动驳回，系统出款失败时，转至人工审核</div>
        </el-form-item>
      </div>
    </el-form>
    <div style="text-align: center;margin-top: 50px;">
      <el-button
        style="width: 150px"
        type="primary"
        @click="gradeSubmitForm('eventsForm')"
        >提交</el-button
      >
    </div>
  </div>
</template>
<script>
import { WithdrawConfiginfo, saveWithdrawConfig } from "@/api/finance/index";
export default {
  data() {
    return {
      loading: true,
      avatarFile: [],
      eventsForm: {
        rate: 0, //提现费率
        min_price: "100.00", //最低提现金额
        is_charge: "1", //免手续费 1开启 2关闭
        avoid_charge_price: "500.00", //免手续费额度
        is_check: "1", //提现审核 1人工审核 2自动审核
      },
      eventsRules: {
        rate: [
          {
            required: true,
            validator: (rule, value, callback) => {
              if (value == "") {
                callback(new Error("请输入手续费率"));
              } else {
                if (Number(value) > 100 || Number(value) < 0) {
                  callback(new Error("费率不能大于100,小于0"));
                } else {
                  callback();
                }
              }
            },
            trigger: "change",
          },
        ],
        min_price: [
          {
            required: true,
            validator: (rule, value, callback) => {
              if (value === "") {
                callback(new Error("请输入最低提现额度"));
              } else {
                let req = /^\d+(\.\d{1,2})?$/;
                if (req.test(value)) {
                  callback();
                } else {
                  callback(new Error("最多只能保留两位小数"));
                }
              }
            },
            trigger: "change",
          },
        ],
        avoid_charge_price: [
          {
            required: true,
            validator: (rule, value, callback) => {
              if (value === "") {
                callback(new Error("请输入免手续费额度"));
              } else {
                let req = /^\d+(\.\d{1,2})?$/;
                if (req.test(value)) {
                  callback();
                } else {
                  callback(new Error("最多只能保留两位小数"));
                }
              }
            },
            trigger: "change",
          },
        ],
      },
    };
  },
  created() {
    this.WithdrawConfiginfoWay();
  },
  methods: {
    WithdrawConfiginfoWay() {
      this.loading = true;
      WithdrawConfiginfo().then((res) => {
        this.loading = false;
        if (res.code !== 200 || res.status !== 1) {
          this.$messages.error(res.msg);
          return;
        }
        this.eventsForm = res.data;
      });
    },
    gradeSubmitForm() {
      this.loading = true;
      saveWithdrawConfig(this.eventsForm).then((res) => {
        this.loading = false;
        if (res.code !== 200 || res.status !== 1) {
          this.$messages.error(res.msg);
          return;
        }
        this.$message({
          message: res.msg,
          type: "success",
        });
      });
    },
  },
};
</script>
<style lang="scss">
.flex-box {
  .el-form-item__content {
    display: -webkit-box;
  }
}

.form-box {
  .form-box-item {
    .el-input {
      width: 250px;
    }

    .el-upload-list--picture-card .el-upload-list__item {
      width: 100px;
      height: 100px;
    }

    .el-upload--picture-card {
      width: 100px;
      height: 100px;
      line-height: 110px;
    }
  }
}
</style>
<style lang="scss" scoped>
.app-container {
  background-color: #FFF;
  .blockquote-box {
    border-left: 8px solid #409eff;
    padding-left: 14px;
    margin: 16px 0;
    height: 36px;
    line-height: 36px;
    background: #fafafa;
    font-size: 14px;
  }

  .form-box {
    

    .form-box-item {
      padding-bottom: 10px;
      padding-right: 20px;
      font-size: 12px;
      color: #999;

      .left20 {
        margin-left: 20px;
      }

      .tipbox {
        width: 380px;
        font-size: 12px;
        color: #999;
        font-weight: 550;
        line-height: 20px;
        margin-top: 6px;
      }
    }
  }
}
</style>